package com.xdf.controller;

import com.google.common.util.concurrent.RateLimiter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class RateLimiterController {

    private RateLimiter rateLimiter = RateLimiter.create(10);

    @RequestMapping("/test")
    public void test() {
        if(rateLimiter.tryAcquire(1000,TimeUnit.MILLISECONDS)){
            System.out.println("请求成功");
        }else {
            System.out.println("等待超时，时间");
        }
    }


}